package com.example.hemengqi


import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity


class AddStudentActivity : AppCompatActivity() {
    private val btnConfirm by lazy { findViewById<android.widget.Button>(R.id.btnConfirm) }
    private val btnCancel by lazy { findViewById<android.widget.Button>(R.id.btnCancel) }
    private val etStudentId by lazy { findViewById<android.widget.EditText>(R.id.etStudentId) }
    private val etStudentName by lazy { findViewById<android.widget.EditText>(R.id.etStudentName) }
    private val etStudentGender by lazy { findViewById<android.widget.EditText>(R.id.etStudentGender) }
    private val etStudentClass by lazy { findViewById<android.widget.EditText>(R.id.etStudentClass) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_student)

        btnConfirm.setOnClickListener {
            val id = etStudentId.text.toString()
            val name = etStudentName.text.toString()
            val gender = etStudentGender.text.toString()
            val className = etStudentClass.text.toString()

            val newStudent = Student(id, name, gender, className)
            val intent = Intent()
            intent.putExtra("newStudent", newStudent)
            setResult(RESULT_OK, intent)
            finish()
        }

        btnCancel.setOnClickListener {
            setResult(RESULT_CANCELED)
            finish()
        }
    }
}